/**
 * 枚举
 */
const { resolve } = require('path')
const glob = require('glob')
const Enums = {}

glob.sync(resolve(__dirname, './modules', '*.js')).forEach(item => {
    const name = item.match(/[0-9A-z_]*\.js$/)[0].split('.')[0]
    Enums[name] = require(`${item}`)
})

function getEnumOptions (_enum) {
    var options = [];
    Object.keys(_enum).forEach(key => {
        options.push({ label: _enum[key], value: ['true', 'false'].includes(key) ? JSON.parse(key) : formatNum(key) });
    });
    return options;
}

function formatNum (key) {
    return !isNaN(+key) ? +key : key
}

const _enumOptionsList = Enums;
Object.keys(_enumOptionsList).forEach(i => {
    const _modules = _enumOptionsList[i];
    Object.keys(_modules).forEach(m => {
        _modules[`${m}Options`] = getEnumOptions(_modules[m]);
    });
});

module.exports = Enums
